//
//  AppDelegate+OpenURL.m
//  NongWanCloud
//
//  Created by YueWen on 2018/2/10.
//  Copyright © 2018年 YueWen. All rights reserved.
//

#import "AppDelegate+OpenURL.h"

#import <WXApi.h>
#import <AlipaySDK/AlipaySDK.h>
#import <UMShare/UMShare.h>

#import "UPPaymentControl.h"
#import "HeziSDK.h"

#import "QDMetroClient-Swift.h"

@implementation QDMetroAppDelegate (OpenURL)


- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options NS_AVAILABLE_IOS(9_0)
{
    BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url options:options];
    
    if (!result) {//支付等回调
        [self payWithUrl:url];//支付
    }
    return result;
}



- (void)payWithUrl:(NSURL *)url
{
    // 活动盒子
    [[HeziSDKManager sharedInstance]dealWithUrl:url];
    
    if ([url.host isEqualToString:@"safepay"]) { //支付宝
        [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"PaymentAliResultNoticationName" object:[AlipaySDK defaultService] userInfo:resultDic];
        }];
    }
    
    else if([url.host isEqualToString:@"pay"] || [url.host isEqualToString:@"opentempsession"]){//微信
        [WXApi handleOpenURL:url delegate:QDPaymentWeixinManager.sharedInstance];
    }
    
    else {//银联
        [UPPaymentControl.defaultControl handlePaymentResult:url completeBlock:^(NSString *code, NSDictionary *data) {
            if (!code) return;
            [[NSNotificationCenter defaultCenter] postNotificationName:@"PaymentUnionResultNoticationName" object:[UPPaymentControl defaultControl] userInfo:@{@"code":code}];
        }];
    }
}


@end
